package com.alibaba.citrus.cr.sales.plan.converter;

import com.alibaba.citrus.cr.sales.plan.model.features.SalesPlanCustomerFeatures;
import com.alibaba.citrus.cr.sales.plan.sdo.SalesPlanStatCustomerSDO;
import com.alibaba.fastjson.JSONObject;
import com.epoch.app.bcorder.sales_plan.plancustomer.model.PlanCustomer;
import com.google.common.collect.Lists;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.Objects;

/**
 * @author luyi
 * @date 2021/9/23 3:27 下午
 */
public class PlanCustomerConverter {


    public static SalesPlanStatCustomerSDO planCustomerDoToSdo(PlanCustomer request){
        if (Objects.isNull(request)){
            return null;
        }
        SalesPlanStatCustomerSDO result = new SalesPlanStatCustomerSDO();
        BeanUtils.copyProperties(request,result);
        result.setPlanId(String.valueOf(request.getPlanId()));
        if (!Objects.isNull(request.getFeatures())){
            SalesPlanCustomerFeatures features = JSONObject.parseObject(request.getFeatures(), SalesPlanCustomerFeatures.class);
/*            result.setCustomerName(features.getCustomerName());
            result.setCustomerAddressName(features.getCustomerAddressName());
            result.setBondType(features.getBondType());*/
        }
        return result;
    }

    public static PlanCustomer planCustomerSdoToDo(SalesPlanStatCustomerSDO request){
        if (Objects.isNull(request)){
            return null;
        }
        PlanCustomer result = new PlanCustomer();
        BeanUtils.copyProperties(request,result);
        result.setPlanId(Long.valueOf(request.getPlanId()));
        SalesPlanCustomerFeatures features = new SalesPlanCustomerFeatures();
/*        features.setCustomerName(request.getCustomerName());
        features.setCustomerAddressName(request.getCustomerAddressName());
        features.setBondType(request.getBondType());*/
/*        features.setContactName(request.getContactName());
        features.setCellphoneNumber(request.getCellphoneNumber());*/
        result.setFeatures(JSONObject.toJSONString(features));
        return result;
    }

    public static List<SalesPlanStatCustomerSDO> planCustomerDoToSdo(List<PlanCustomer> requestList){
        if (CollectionUtils.isEmpty(requestList)){
            return null;
        }
        List<SalesPlanStatCustomerSDO> result = Lists.newArrayListWithCapacity(requestList.size());
        for (PlanCustomer request : requestList) {
            result.add(planCustomerDoToSdo(request));
        }
        return result;
    }

    public static List<PlanCustomer> planCustomerSdoToDo(List<SalesPlanStatCustomerSDO> requestList){
        if (CollectionUtils.isEmpty(requestList)){
            return null;
        }
        List<PlanCustomer> result = Lists.newArrayListWithCapacity(requestList.size());
        for (SalesPlanStatCustomerSDO request : requestList) {
            result.add(planCustomerSdoToDo(request));
        }
        return result;
    }

}
